
package pencarian;
import java.util.ArrayList;

public class Searching {
    //atribut
    private ArrayList<Coordinat> CoordinatResult; //tempat penyimpan hasil yang akan dikeluarkan oleh algoritma sesuai mode yg dipilih
    //method
    public Searching(int mode,Input inputan,String namafile){
        //mode:0=BFS,1=DFS,2=GBF,3=AStar,4=UCS
        switch(mode){
            case 0:
                BFS doBFS = new BFS(inputan,namafile);
                doBFS.doSearch();
                CoordinatResult = new ArrayList<Coordinat>(doBFS.getSolution());
                break;
            case 1:
                DFS doDFS = new DFS(inputan,namafile);
                CoordinatResult = new ArrayList<Coordinat>(doDFS.getSolution());
                break;
            case 2:
                GBF doGBF = new GBF(inputan,namafile);
                CoordinatResult = new ArrayList<Coordinat>(doGBF.getSolution());
                break;
            case 3:
                AStar doAStar = new AStar(inputan,namafile);
                CoordinatResult = new ArrayList<Coordinat>(doAStar.getSolution());
                break;
            case 4:
                UCS doUCS = new UCS(inputan,namafile);
                CoordinatResult = new ArrayList<Coordinat>(doUCS.getSolution());
                break;
            default:
                break;
        }  
    }
    public ArrayList<Coordinat> getCoordinatResult(){
        return CoordinatResult;
    }
    public void showCoordinatResult(){
        if(CoordinatResult.size() == 1){
            CoordinatResult.get(0).showCoordinat();
        }
        else{
            System.out.print("Solution : ");
            CoordinatResult.get(0).showCoordinat();
            for(int i=1;i<=CoordinatResult.size()-1;i++){
                System.out.print("->");
                CoordinatResult.get(i).showCoordinat();
            }
        }
    }
}
